import json
import time
from datetime import datetime
import requests
import traceback

# from BinanceConfig import proxies
# from myEncoder import MyEncoder
def send_import_ding_message(message, account = '', at_all = 0):
    try:
        url = 'https://oapi.dingtalk.com/robot/send?access_token=0a3dd538bf441fc0bd20141ccbb3d8712f794e3065446429af0c1796d00e3009'

        HEADERS = {
            "Content-Type": "application/json ;charset=utf-8 "
        }
        String_textMsg = {
            "msgtype": "text",
            "text": {"content": f'[{account}]：\n{message}'},
            "at": {
                "atMobiles": [
                ],
                "isAtAll": at_all  #是否艾特全体成员
            }
        }
        String_textMsg = json.dumps(String_textMsg)
        res = requests.post(url, data=String_textMsg, headers=HEADERS)
        # print(res.text)
        return res.text
    except Exception as error:
        return f'钉钉发送失败，{error}'

def set_dingding_robot(content = []):
    ding_msg = [
        f'{time.strftime("%Y-%m-%d", time.localtime(int(time.time())))}:']
    ding_msg.extend(list(content))
    ding = "\n".join(ding_msg)
    res = send_import_ding_message(f'{ding}')

if __name__ == '__main__':
    content = [
        f'测试测试：'
    ]
    set_dingding_robot(content)
